require "FairyGUI"

BagWindow = fgui.window_class();

function BagWindow:ctor()
	-- body
end

function BagWindow:OnInit()
	-- body
	self.contentPane = UIPackage.CreateObject("Bag", "BagWin").asCom;
	self:Center();
	self.modal = true;

	self._list = self.contentPane:GetChild("list").asList;
	self._list.onClickItem:Add(self.__clickItem, self);
	print(self);
	self._list.itemRenderer = self.RenderListItem;
	self._list.numItems = 45;
end

function BagWindow.RenderListItem(index, obj)
	-- body
	print("renderlistitem", index, obj);
	local button = obj;

	local iconIndex = PLKUtils.CreateIntRandomValue(0,10);
	local titleIndex = PLKUtils.CreateIntRandomValue(0,100);

	button.icon = "i" .. iconIndex;
	button.title = "" .. titleIndex;
	print("RenderListItem: "..iconIndex.." "..titleIndex);
end

function BagWindow:DoShowAnimation()
	self:SetScale(0.1, 0.1);
	self:SetPivot(0.5, 0.5);
	local tween = self:TweenScale(Vector2(1,1), 0.3);
	tween:SetEase(DG.Tweening.Ease.OutQuad):OnComplete(self.base.OnShown);
end

function BagWindow:__clickItem(content)
	local item = content.data;
	self.contentPane:GetChild("n11").asLoader.url = item.icon;
	self.contentPane:GetChild("n13").text = item.icon;

	print("__clickItem: "..item.icon);
end

function BagWindow:DoHideAnimation()
	local Self = self;
	self:TweenScale(Vector2(0.1,0.1), 0.3):SetEase(DG.Tweening.Ease.OutQuad):OnComplete(function () self:HideImmediately(); end);
end